layui.use(['form','layer','upload','laydate','treeSelect','layedit','tableSelect','table'],function(){
        var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
    var upload = layui.upload;
    var laydate = layui.laydate;
    var treeSelect= layui.treeSelect;//树形下拉框
    treeSelect.render({
        elem: '#categoryName',
        data: '/admin/productCategory/treelist',
        type: 'get',
        placeholder: '默认添加首级分类',// 占位符
        search: true,// 是否开启搜索功能：true/false，默认false
        click: function(data){
            $("#categoryName").val(data.current.name);
            $("#categoryId").val(data.current.id);
        },
        success: function (data) { // 加载完成后的回调函数
            $("#categoryName").val(data.data[0].name);
            $("#categoryId").val(data.data[0].id);
        }
    });
    treeSelect.render({
        elem: '#storageName',
        data: '/admin/storage/treelist',
        type: 'get',
        placeholder: '默认添加首级分类',// 占位符
        search: true,// 是否开启搜索功能：true/false，默认false
        click: function(data){
            $("#storageId").val(data.current.storageId);
            $("#storageName").val(data.current.name);
        },
        success: function (data) { // 加载完成后的回调函数
            $("#storageName").val(data.data[0].name);
            $("#storageId").val(data.data[0].storageId);
        }
    });
    var date = new Date();
    laydate.render({
        elem: '#supplyDate'
        ,value: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()   //必须遵循format参数设定的格式  + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds()
    });



form.on("submit(addProduce)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
     $.post("/admin/product/add",{
         categoryId:$("#categoryId").val(),
         produceId: $("#produceId").val(),
         produceName: $("#produceName").val(),
         supplier: $("#supplier").val(),
         produceNo : $("#produceNo").val(),
         buyer: $("#buyer").val(),
         buyNum : $("#buyNum").val(),
         unit: $("#unit").val(),
         price : $("#price").val(),
         supplyDate : new Date(Date.parse($("#supplyDate").val())),
         storageId : $("#storageId").val(),
         threshold : $("#threshold").val(),
         produceBrief : $("#produceBrief").val(),
         remarks:$("#remarks").val()
        //  : $(".produceVideo").val(),

         },function(res){
            //成功后返回的数据res，这里可以写一些成功后的操作
         })
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("产品添加成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        return false;
    })

})